Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

396
Visualizações
Simple API call with "Bearer" token Authorization using Ajax

My problem is that I couldn't fetch data from API using Ajax.

I'm using a JWT token for authentication and when I call the API from Postman, I get the data successfully.

enter image description here

However, when calling the API using ajax, an ERR_ABORTED 401 (Unauthorized) error is detected. Here's the code:

$.ajax({
    type: "GET",
    url: API_URL,
    dataType: 'jsonp',
    contentType: "application/json",
    headers: {
        "Cache-Control": "no-cache",
        "Authorization": "Bearer " + access_token,
    },
    data: {}, 
    success: function(resp){
        console.log(resp)
    }, 
    error: function(error){
    }    
})

Also, I get the same error when I copy and use the code snippet generated by POSTMAN.

enter image description here

I've searched a lot of answers for this and applied them, but it doesn't work for me.

Can someone help with this?

Thank you in advance.

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda